package com.wangp.procurement.convert;

import com.wangp.procurement.po.GoodsDO;
import com.wangp.procurement.vo.GoodsVO;
import org.springframework.beans.BeanUtils;

import java.util.ArrayList;
import java.util.List;

public class GoodsConverter {
    /**
     * 将GoodsVO转换为GoodsDO
     * @param goodsVO 货物VO对象
     * @return 货物DO对象
     */
    public static GoodsDO convertToGoodsDO(GoodsVO goodsVO) {
        if (goodsVO == null) {
            return null;
        }
        GoodsDO goodsDO = new GoodsDO();
        goodsDO.setId(goodsVO.getId());
        goodsDO.setProcurementManagementId(goodsVO.getProcurementManagementId());
        goodsDO.setGoodsName(goodsVO.getGoodsName());
        goodsDO.setProcurementPlace(goodsVO.getProcurementPlace());
        goodsDO.setDestination(goodsVO.getDestination());


        return goodsDO;
    }

    /**
     * 将GoodsDO转换为GoodsVO
     * @param goodsDO 货物DO对象
     * @return 货物VO对象
     */
    public static GoodsVO convertToGoodsVO(GoodsDO goodsDO) {
        if (goodsDO == null) {
            return null;
        }
        GoodsVO goodsVO = new GoodsVO();
        goodsVO.setId(goodsDO.getId());
        goodsVO.setProcurementManagementId(goodsDO.getProcurementManagementId());
        goodsVO.setGoodsName(goodsDO.getGoodsName());
        goodsVO.setProcurementPlace(goodsDO.getProcurementPlace());
        goodsVO.setDestination(goodsDO.getDestination());


        return goodsVO;
    }


    public static List<GoodsVO> convertToGoodsVOList(List<GoodsDO> goodsDOList) {
        List<GoodsVO> goodsVOList = new ArrayList<>();
        for (GoodsDO goodsDO : goodsDOList) {
            GoodsVO goodsVO = convertToGoodsVO(goodsDO);
            goodsVOList.add(goodsVO);
        }
        return goodsVOList;
    }
    public static List<GoodsDO> convertToGoodsDOList(List<GoodsVO> goodsVOList) {
        List<GoodsDO> goodsDOList = new ArrayList<>();
        for (GoodsVO goodsVO : goodsVOList) {
            GoodsDO goodsDO = convertToGoodsDO(goodsVO);
            goodsDOList.add(goodsDO);
        }
        return goodsDOList;
    }

}